import {resolve} from "path"
import { defineConfig,loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
//自动导入
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
const env=loadEnv("development","./")
const proxy_url=env.VITE_PROXY_URL
// https://vitejs.dev/config/
export default defineConfig({
  resolve:{
   alias:{
    '@':resolve(__dirname,"src")
   }
  },
   plugins: [
    vue(),
    AutoImport({
      imports: [
        'vue',
        'vue-router',
        {
          'naive-ui': [
            'useDialog',
            'useMessage',
            'useNotification',
            'useLoadingBar'
          ]
        }
      ],
      dts:"./src/auto-imports.d.ts"

    }),
    Components({
      resolvers: [NaiveUiResolver()],
      dts:"./src/components.d.ts"
    })
  ],
  server: {
    proxy: {
      "/api": {
        target: proxy_url,
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, " "),
      },
      "/multi-avatar": {
        target:proxy_url,
        changeOrigin: true,
      },
      "/avatars": {
        target: proxy_url,
        changeOrigin: true,
      },
    },
  },
})
